package org.liang.controller;

import org.liang.util.AjaxResult;
import org.liang.utils.SendEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/email")
public class QQEmailSendController {

    @Autowired
    private JavaMailSender javaMailSender;

    @PostMapping("/send/{emailName}/{type}")
    public AjaxResult sendQQEmail(@PathVariable("emailName") String emailName, @PathVariable("type") Integer type) {
        String text;
        if (type == 0) {
            //发送邮件
            text = "<h1>蓉礼购</h1>\n" +
                    "      <p>\n" +
                    "          感谢您入驻我们平台！我们的员工在1-2个工作日内对您递交的申请进行审核，请耐心等待审核结果，再次感谢您的大力支持！\n" +
                    "      </p>\n";
        } else {
            //发送邮件
            text = "<h1>蓉礼购</h1>\n" +
                    "      <p>\n" +
                    "          恭喜您入驻审核通过！，xxx先生，您在某年某月某时申请蓉礼购店铺入驻通过，请点击下方链接进行激活，感谢您的大力支持！\n" +
                    "      </p>\n" +
                    "      <a href=\"http://127.0.0.1:10030/apis/sys/tenant/activation/" + emailName + "\">\n" +
                    "          点我激活\n" +
                    "      </a>";
        }
        SendEmail.sendQQEmail(emailName, emailName, text, javaMailSender);
        return AjaxResult.success();
    }

    //店铺入驻审核驳回
    @PostMapping("/reviewReject/{emailName}/{region}/{desc}")
    public AjaxResult reviewReject(@PathVariable("emailName") String emailName,
                                   @PathVariable("region") String region,
                                   @PathVariable("desc") String desc) {
        //发送邮件
        String text = "<h1>蓉礼购</h1>\n" +
                "    <p>问题类型：" + region + "</p>\n" +
                "    <p>问题原因：" + desc + "</p>\n" +
                "    <p>抱歉，xxx先生,您在某年某月某时申请的蓉礼购店铺入驻审核未通过！请点击下方链接重新进行申请，感谢您的大力支持！</p>\n" +
                "    <a href=\"http://127.0.0.1:8081/#/shopRegister?email=" + emailName + "\">\n" +
                "      蓉车宝http://127.0.0.1:8081/#/shopRegister\n" +
                "    </a>";
        SendEmail.sendQQEmail(emailName, emailName, text, javaMailSender);
        return AjaxResult.success();
    }
}
